def isPrime(x):    
    if x == 1:
        return False    
    sort = True    
    j = x - 1    
    while j > 1:    
        if not x % j:    
            sort = False                
            break    
        j -= 1        
    return sort   
      
n = input()  
p = []
if len(n)!=4 or not n.isdigit():
    print(0)
else:
    for i in range(len(n)):  
        for j in range(i + 1,len(n) + 1):  
            x = int(n[i:j]) 
            if isPrime(x):  
                p += [x]
    if p:
        print(max(p))
    else:
        print(0)
